package 实验2;

public class Course {
	private String courseName;
	private int courseId;
	private float credit;
	private Teacher teacher;
	private String courseAddress;
	private Student[] students;
 
	public Course(int courseId,String courseName,String courseAddress,float credit,Teacher teacher) {
		super();
		this.courseId = courseId;
		this.courseName = courseName;
		this.courseAddress = courseAddress;
		this.credit = credit;
		this.setTeacher(teacher);
		students = new Student[30];
	}
	public Course(int courseId,String courseName,String courseAddress,float credit) {
		super();
		this.courseId=courseId;
		this.courseName=courseName;
		this.courseAddress=courseAddress;
		this.credit=credit;
		students = new Student[30];
		}
	public Course(int courseId,String courseName,String courseAddress) {
		super();
		this.courseId=courseId;
		this.courseName=courseName;
		this.courseAddress=courseAddress;
		students = new Student[30];
		}
	public Course(int courseId,String courseName) {
		super();
		this.courseId=courseId;
		this.courseName=courseName;
		students = new Student[30];
		}
	
	public Course() {   
		super();
		students = new Student[30];
		}
 
 public Course(int courseId2, String courseName2, String courseAddress2, String string, Teacher teacher1) {
	
	}

	public void setId(int id){
		this.courseId=id;
	}
	public int getId(){
		return this.courseId;
	}
	public void setName(String name){
		this.courseName=name;
	}
	public String getName(){
		return this.courseName;
	}
	public void setCredit(float credit ){
		this.credit=credit;
	}
	public float getCredit(){
		return this.credit;
	}
	public Teacher getTeacher() {
		return teacher;
	}
	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}
	public void setcourseAddress(String courseAddress) {
		this.courseAddress = courseAddress;
	}
 

	public boolean addStudent(Student stu){
		boolean flag = false;
				for(int i=0;i<students.length;i++){
					if(students[i]==null){
						students[i]=stu;
						flag=true;
						break;
					}
				}
	 return flag;
	}

    public boolean removeStudent(Student stu){
    	boolean flag = false;
    		for(int i=0;i<students.length;i++){
    			if(students[i] == stu){
    				students[i] = null;
    				flag = true;
    				break;
				}
			}
	 return flag;
	}

	public void displayStudent(){
		System.out.println("选择的课程："+this.courseName+"的学生有:");
		for(Student s:students){
			if(s!=null){
				System.out.print(s.getStuName()+" ");
				}
			}
		System.out.println();
		}
}
